Loading
notes intro/old submit AP Problems the dump links
 

2005 - FR2 Solution

 

Part (a)

public class Advance extends Ticket
{
  private int daysInAdvance;

  public Advance (int days)
  {
    daysInAdvance = days;
  }

  public double getPrice()
  {
    if (daysInAdvance >= 10)
      return 30.0;
    else
      return 40.0;
  }
}

Part (b)

public class StudentAdvance extends Advance 1
{
  public StudentAdvance(int days)
  {
    super(days);
  }

  public double getPrice()
  {
    return super.getPrice() / 2;
  }

  public String toString()
  {
    return super.toString() + " (student ID required)"; 2
  }
}